package com.yfp.goods.enums;

import cn.hutool.core.util.ObjectUtil;
import com.yfp.common.core.exception.ServiceException;

import java.util.Date;

public enum PlanTimeEnum {

    //进行中 已结束 未开始
    UNDERWAY("进行中", "Ongoing"),
    END("已结束", "Invalidated"),
    NOT_START("未开始", "End");

    private String name;
    private String value;

    PlanTimeEnum(String name, String value) {
        this.name = name;
        this.value = value;
    }

    public String getName() {
        return name;
    }

    public String getValue() {
        return value;
    }

    public static String getPlanTimeEnumNameByVal(String value) {
        for (PlanTimeEnum planTimeEnum : PlanTimeEnum.values()) {
            if (planTimeEnum.getValue().equals(value)) {
                return planTimeEnum.getName();
            }
        }
        return null;
    }

    public static PlanTimeEnum getPlanTimeEnumByTime(Date startTime, Date endTime){
        if (ObjectUtil.hasEmpty(startTime, endTime)) throw new ServiceException("投放计划开始/结束时间为空");
        Date date = new Date();
        if (startTime.after(date)){
            return NOT_START;
        } else if (startTime.before(date) && endTime.after(date)) {
            return UNDERWAY;
        }else{
            return END;
        }
    }
}
